package com.wang.common.http;

import java.io.IOException;
import java.util.HashMap;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class IHttpRequesterImpl extends AbstractRequester {

	@Override
	public String doRequest(String url) throws ClientProtocolException, IOException {

		return request(url, null);
	}

	@Override
	public String doPost(String url, HashMap<String, String> paramMap)
			throws ClientProtocolException, IOException {

		return request(url, paramMap);
	}

	@Override
	public String doRequest(String url, HashMap<String, String> paramMap,
			HashMap<String, String> propterties) {

		return null;
	}

	private String request(String url, HashMap<String, String> hashmap)
			throws ClientProtocolException, IOException {

		String ret = null;
		HttpGet httpget = new HttpGet(url);
		HttpClient httpClient = new DefaultHttpClient();

		HttpResponse httpResponse = httpClient.execute(httpget);

//		if(null!=hashmap){
//			List<NameValuePair> params=new ArrayList<NameValuePair>();
//            for(Entry<String, String> entry: hashmap.entrySet()){
//            	params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
//            }
//		}
		
		
		if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

			ret = EntityUtils.toString(httpResponse.getEntity());

		} else {

		}

		return ret;
	}

}
